﻿using shop.Bll;
using shop.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using unvell.ReoGrid;
using shop.Bll.Logi;


namespace shop.Logi
{
    public partial class LogiCalculateForm : DockContent
    {

        shop.Bll.trade.TradeBll bll = new shop.Bll.trade.TradeBll();


        public LogiCalculateForm()
        {
            InitializeComponent();
        }

        private async void btn_Query_Click(object sender, EventArgs e)
        {
            var begin = box_begin.Value.Value;
            var end = box_end.Value.Value;

            var list = new List<stockout_order_query_tradeItem>();


            //while (true)
            //{
                var res = await new QueryLogisticsBll().stockout_order_query_trade(begin, end, 0);
                list.AddRange(res.stockout_list);
                if (res.stockout_list == null || res.stockout_list.Count==0)
                {
                    //break;
                }
            //}

            //new unvell.ReoGrid.GridDataBuilder(this.grid1)
            //    .UseData(list)
            //    //.AutoCreateColumns()
            //    .End();


            // 货品成本	货品总成本	单品支付金额	邮费	订单编号	原始单号	订单类型	仓库	店铺	商家编码	收货地区	物流公司	快递老板	客服备注	发货时间

            var data = list
                .SelectMany(a => a.details_list
                    .Select(c => new
                    {
                        a,
                        c.spec_no,

                    })
                )
                .Select(a => new
                {
                    物流单号 = a.a.logistics_no,
                    货品数量 = a.a.goods_count,
                    预估邮资 = a.a.calc_post_cost,
                    //货品成本=a.goods_total_cost,
                    货品总成本 = a.a.goods_total_cost,
                    //单品支付金额= 
                    邮费 = a.a.post_fee,
                    订单编号 = a.a.trade_no,
                    原始单号 = a.a.src_trade_no,
                    订单类型 = stockout_order_query_tradeResult.GetTradeTypeText(a.a.trade_type),
                    仓库 = a.a.warehouse_name,
                    店铺 = a.a.shop_name,
                    商家编码 = a.spec_no,
                    收货地区 = a.a.receiver_district,
                    收货城市 = a.a.receiver_city,
                    物流公司 = a.a.logistics_name,
                    快递老板 = a.a.logistics_template_id,
                    客服备注 = a.a.cs_remark,
                    发货时间 = a.a.consign_time,
                })
                .ToList();



        }



    }
}
